﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.ExceptionHanding;

namespace LX.Data
{
    public abstract class PersistentContext : IPersistentContext
    {

        protected PersistentContext()
        {
        }

        protected bool iscommited = false;


        public abstract IQueryable<T> GetQuery<T>() where T : class,IEntity;

        public  void Commit()
        {
            iscommited = true;
            CommitContext();
        }

        protected abstract void CommitContext();

        public abstract void Add<T>(T model) where T : class,IEntity;

        public abstract void Delete<T>(T model) where T : class,IEntity;


        public void Dispose()
        {
            if(!iscommited)
            {
                Commit();
            }
        }


        public abstract T Get<T>(object id) where T : class,IEntity;
    }
}
